package com.monitor.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.monitor.system.domain.vo.AbnormalCollectionAlarmVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.monitor.common.annotation.Log;
import com.monitor.common.core.controller.BaseController;
import com.monitor.common.core.domain.AjaxResult;
import com.monitor.common.enums.BusinessType;
import com.monitor.system.domain.AbnormalCollectionAlarm;
import com.monitor.system.service.IAbnormalCollectionAlarmService;
import com.monitor.common.utils.poi.ExcelUtil;
import com.monitor.common.core.page.TableDataInfo;

/**
 * 异常采集告警Controller
 * 
 * @author monitor
 * @date 2024-06-06
 */
@Api("异常采集告警Controller")
@RestController
@RequestMapping("/system/alarm")
public class AbnormalCollectionAlarmController extends BaseController
{
    @Autowired
    private IAbnormalCollectionAlarmService abnormalCollectionAlarmService;

    /**
     * 查询异常采集告警列表
     */
    @ApiOperation("查询异常采集告警列表")
    @PreAuthorize("@ss.hasPermi('system:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(AbnormalCollectionAlarm abnormalCollectionAlarm)
    {
        startPage();
        List<AbnormalCollectionAlarm> list = abnormalCollectionAlarmService.selectAbnormalCollectionAlarmList(abnormalCollectionAlarm);
        return getDataTable(list);
    }

    /**
     * 导出异常采集告警列表
     */
    @ApiOperation("导出异常采集告警列表")
    @PreAuthorize("@ss.hasPermi('system:alarm:export')")
    @Log(title = "异常采集告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbnormalCollectionAlarm abnormalCollectionAlarm)
    {
        List<AbnormalCollectionAlarm> list = abnormalCollectionAlarmService.selectAbnormalCollectionAlarmList(abnormalCollectionAlarm);
        ExcelUtil<AbnormalCollectionAlarm> util = new ExcelUtil<AbnormalCollectionAlarm>(AbnormalCollectionAlarm.class);
        util.exportExcel(response, list, "异常采集告警数据");
    }

    /**
     * 获取异常采集告警详细信息
     */
    @ApiOperation("获取异常采集告警详细信息")
    @PreAuthorize("@ss.hasPermi('system:alarm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(abnormalCollectionAlarmService.selectAbnormalCollectionAlarmById(id));
    }

    /**
     * 新增异常采集告警
     */
    @ApiOperation("新增异常采集告警")
    @PreAuthorize("@ss.hasPermi('system:alarm:add')")
    @Log(title = "异常采集告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AbnormalCollectionAlarm abnormalCollectionAlarm)
    {
        return toAjax(abnormalCollectionAlarmService.insertAbnormalCollectionAlarm(abnormalCollectionAlarm));
    }

    /**
     * 修改异常采集告警
     */
    @ApiOperation("修改异常采集告警")
    @PreAuthorize("@ss.hasPermi('system:alarm:edit')")
    @Log(title = "异常采集告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AbnormalCollectionAlarm abnormalCollectionAlarm)
    {
        return toAjax(abnormalCollectionAlarmService.updateAbnormalCollectionAlarm(abnormalCollectionAlarm));
    }

    /**
     * 删除异常采集告警
     */
    @ApiOperation("删除异常采集告警")
    @PreAuthorize("@ss.hasPermi('system:alarm:remove')")
    @Log(title = "异常采集告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(abnormalCollectionAlarmService.deleteAbnormalCollectionAlarmByIds(ids));
    }

    /**
     * 可视化分析查询
     */
//    @PreAuthorize("@ss.hasPermi('system:alarm:showTable')")

    @ApiOperation("可视化分析查询")
    @PostMapping("/showTable")
    public AbnormalCollectionAlarmVo showTable(@RequestBody AbnormalCollectionAlarmVo vo)
    {
        AbnormalCollectionAlarmVo alarmVo = abnormalCollectionAlarmService.selectAbnormalCollectionAlarmListNew(vo);
        return alarmVo;
    }

    /**
     * 可视化分析查询(当日)
     */
    @ApiOperation("可视化分析查询(当日)")
    @PostMapping("/showOtherTable")
    public AbnormalCollectionAlarmVo showOtherTable(@RequestBody AbnormalCollectionAlarmVo vo)
    {
        AbnormalCollectionAlarmVo alarmVo = abnormalCollectionAlarmService.selectAbnormalCollectionAlarmListNew(vo);
        return alarmVo;
    }
}
